Polytypic Uni cation

نویسنده

  • Johan Jeuring
چکیده

Uni cation or two way pattern matching is the process of solving an equation involving two rst order terms with variables Uni cation is used in type inference in many pro gramming languages and in the execution of logic programs This means that uni cation algorithms have to be written over and over again for di erent term types Many other functions also make sense for a large class of datatypes examples are pretty printers equality checks maps etc They can be de ned by induction on the structure of user de ned datatypes Implementations of these functions for di erent datatypes are closely related to the structure of the datatypes We call such functions polytypic This paper describes a uni cation algorithm parametrised on the type of the terms and shows how to use polytypism to obtain a uni cation algorithm that works for all regular term types Introduction In simple pattern matching a pattern a string containing wild cards is matched with a normal string to determine if the string is an instance of the pattern This can be generalised in at least two directions we can allow the second string to contain wild cards too thus making the matching symmetric or we can allow more complicated terms than strings By combining these two generalisations we obtain uni cation A uni cation algorithm tries to nd a most general uni er mgu of two terms The most general uni er of two terms is the smallest substitution of terms for variables such that the substituted terms become equal Use of uni cation is widespread it is used in type inference algorithms rewriting systems compilers etc Knight Descriptions of uni cation algorithms normally deal with a general datatype of terms containing variables and applications of constructors to terms but each real implementation uses one speci c instance of terms and a specialised version of the algorithm for this term type This paper describes a functional uni cation program that works for all regular term types The program is an example of a polytypic function Jeuring If two rst order terms are uni able their mgu is unique Robinson P Jansson and J Jeuring Function length List a Int which counts the number of occurrences of a s in a list and the similar function numOfElems Tree a Int which counts the number of occurrences of a s in a tree are both instances of a more general function size d a Int Function size is not only polymorphic in a but also in the type constructor d In the same way we can generalise the function map a b List a List b into a function pmap a b d a d b so that it too works for trees and other similar datatypes We call such functions polytypic functions For an introduction to the basic ideas of polytypic functions see Jeuring Jansson and for a more theoretical treatment of polytypism Bird et al and de Moor In this paper we show that by parametrising the uni cation algorithm by the datatype for terms we can separate the core of the algorithm from the parts depending on the speci c datatype and by abstracting away from the type constructor dependence in the datatype dependent part we obtain a polytypic program Thus we have one implementation of uni cation that works for many di erent term types leaving the specialisation to the compiler The core of the uni cation algorithm is written in Haskell and the polytypic part is written in the Haskell extension PolyP Jansson Jeuring The full code is available from http www cs chalmers se patrikj unify Uni cation In this section we will specify and implement a functional uni cation algorithm We start with an example Consider the uni cation of the two terms f x f a b and f g y a y where x and y are variables and f g a and b are constants Since both terms have an f on the outermost level these expressions can be uni ed if x can be uni ed with g y a and f a b can be uni ed with y As these two pairs of terms are uni ed by the substitution fx g y a y f a b g the original pair of terms is also uni ed by applying the substitution yielding the uni ed term f g f a b a f a b Terms In the uni cation literature a term is usually de ned as either a variable or an application of a constructor to zero or more terms Var is a set of variables and Con is a set of constructor constants T v j c T Tarity c v Var c Con We instead focus on the three properties of the type of terms we need to de ne uni cation We need to know the children immediate subterms of a term and how to update them

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Type-Indexed Data Types

A polytypic function is a function that can be instantiated on many data types to obtain data type speci c functionality. Examples of polytypic functions are the functions that can be derived in Haskell, such as show , read , and ( ). More advanced examples are functions for digital searching, pattern matching, uni cation, rewriting, and structure editing. For each of these problems, we not onl...

متن کامل

Polyp | a Polytypic Programming Language Extension

Many functions have to be written over and over again for di erent datatypes, either because datatypes change during the development of programs, or because functions with similar functionality are needed on di erent datatypes. Examples of such functions are pretty printers, debuggers, equality functions, uni ers, pattern matchers, rewriting functions, etc. Such functions are called polytypic f...

متن کامل

Polarity-driven polytypic branching in cu-based quaternary chalcogenide nanostructures.

An appropriate way of realizing property nanoengineering in complex quaternary chalcogenide nanocrystals is presented for Cu2CdxSnSey(CCTSe) polypods. The pivotal role of the polarity in determining morphology, growth, and the polytypic branching mechanism is demonstrated. Polarity is considered to be responsible for the formation of an initial seed that takes the form of a tetrahedron with fou...

متن کامل

Matching and Uni cation in Rewrite Theories

\Semantic uni cation" is the process of generating a basis set of substitutions (of terms for variables) that makes two given terms equal in a speci ed theory. Semantic uni cation is an important component of some theorem provers. \Semantic matching," a simpler variant of uni cation, where the substitution is made in only one of the terms, has potential usage in programming language interpreter...

متن کامل

Syntactic Uni cation Problems under Constrained Substitutions

Some kind of practical problems such as security veri cation of cryptographic protocols can be described as a problem to accomplish a given purpose by using limited operations and limited materials only. To model such problems in a natural way, uni cation problems under constrained substitutions have been proposed. This paper is a collection of results on the decidability and the computational ...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 1998